/**
 *
 * @type {{getQueryString: $.webUtil.getQueryString, syncAjax: $.webUtil.syncAjax}}
 */
$.webUtil = {
    //获取请求过来的参数
    getQueryString: function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return decodeURIComponent(r[2]);
        return null;
    },
    //ajax同步获取数据
    syncAjax: function (url, param, type) {
        var $data = [];
        $.ajax({
            type: type || 'post',
            url: url,
            async: false,
            data: param || {},
            dataType: 'json',
            success: function (data) {
                $data = data;
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $data = 'status:' + XMLHttpRequest.status + ' readyState:' + XMLHttpRequest.readyState + ' textStatus:' + textStatus;
                console.log(errorThrown);
            }
        });
        return $data;
    },

    //ajax异步获取数据
    async: function (url, param, type) {
        var $data = [];
        $.ajax({
            type: type || 'post',
            url: url,
            contentType:"application/json",
            async: false,
            data: param || {},
            dataType: 'json',
            success: function (data) {
                $data = data;
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $data = 'status:' + XMLHttpRequest.status + ' readyState:' + XMLHttpRequest.readyState + ' textStatus:' + textStatus;
                console.log(errorThrown);
            }
        });
        return $data;
    }

};
